<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/share/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="width=device-width" />
    <script src="${ctx}/admin/scripts/jquery/jquery-1.10.2.min.js"></script>
    <link href="${ctx}/admin/styles/learun-login.css" rel="stylesheet" />
    <link href="${ctx}/admin/styles/font-awesome.min.css" rel="stylesheet" />
    <script src="${ctx}/admin/scripts/plugins/jquery.md5.js"></script>
    <script src="${ctx}/admin/scripts/plugins/cookie/jquery.cookie.js"></script>
    <script src="${ctx}/admin/scripts/plugins/dialog/dialog.js"></script>
    <script src="${ctx}/admin/scripts/utils/learun-ui.js"></script>
    <script src="${ctx}/admin/scripts/plugins/validator/validator.js"></script>
    <script src="${ctx}/admin/scripts/plugins/tipso.min.js"></script>
<title>驾照考试管理平台</title>
</head>
<body class="aaabody">
    <div class="wrap">
        <div style="text-align: center;">
            <img src="${ctx}/admin/Images/on-line.png" style="border-radius: 96px; margin-bottom: -48px;" />
        </div>
        <div id="loginform" class="container">
            <fieldset class="box">
                <legend>登录信息</legend>
                <dl class="form">
                    <dd>
                        <input id="username" type="text" class="px" placeholder="请输入账号"></dd>
                    <dd>
                        <input id="password" type="password" class="px" placeholder="请输入密码"></dd>
                    <dd style="overflow: hidden;">
                        <div style="float: left; width: 65%">
                            <input id="verifycode" maxlength="4" type="text" class="px" placeholder="图片验证码">
                        </div>
                        <div style="float: left; width: 35%">
                            <img id="login_verifycode" class="img_verifycode" src="${ctx}/login/VerifyCode" width="100" height="30" alt="点击切换验证码"
                                title="点击切换验证码" style="cursor: pointer; padding-top: 2px; padding-left: 5px;" />
                        </div>
                    </dd>
                    <dd style="display:none;">
                        <select id="UItheme" class="ps" style="padding-left:2px;">
                            <option value="1">主题风格-经典版</option>
                            <option value="2" selected>主题风格-风尚版</option>
                            <option value="3">主题风格-炫动版</option>
                        </select>
                    </dd>
                    <dd class="btn">
                        <button id="btnlogin" type="button" class="pn"><span>登录</span></button>
                    </dd>
                </dl>
            </fieldset>
        </div>
    </div>
    <div class="copyright">
        CopyRight M
    </div>
<script type="text/javascript">
	var isIE = !!window.ActiveXObject;
	var isIE6 = isIE && !window.XMLHttpRequest;
	if (isIE6) {
	    window.location.href =  "${ctx}/Error/ErrorBrowser";
	}
  	$(function(){
  	})
  	//回车键
        document.onkeydown = function (e) {
            if (!e) e = window.event;
            if ((e.keyCode || e.which) == 13) {
                var btlogin = document.getElementById("btnlogin");
                CheckLogin(0);
            }
        }
  	
  //初始化
    $(function () {
        $(".wrap").css("margin-top", ($(window).height() - $(".wrap").height()) / 2 - 35);
        $(window).resize(function (e) {
            $(".wrap").css("margin-top", ($(window).height() - $(".wrap").height()) / 2 - 35);
            e.stopPropagation();
        });
        //登录按钮事件
        $("#btnlogin").click(function () {
            var $username = $("#username");
            var $password = $("#password");
            var $verifycode = $("#verifycode");
            if ($username.val() == "") {
                $username.focus();
                formMessage('请输入账户或手机号或邮箱。');
                return false;
            } else if ($password.val() == "") {
                $password.focus();
                formMessage('请输入密码。');
                return false;
            } else if ($verifycode.val() == "") {
                $verifycode.focus();
                formMessage('请输入验证码。');
                return false;
            } else {
                CheckLogin(0);
            }
        })
        //点击切换验证码
        $("#login_verifycode").click(function () {
            $("#verifycode").val('');
            $("#login_verifycode").attr("src", "${ctx}/login/VerifyCode?time=" + Math.random());
        });
    })
    //登录验证
    function CheckLogin(autologin) {
        $("#btnlogin").addClass('active').attr('disabled', 'disabled');
        $("#btnlogin").find('span').hide();

        var username = $.trim($("#username").val());
        var password = $.trim($("#password").val());
        var verifycode = $.trim($("#verifycode").val());
        $.ajax({
            url: "${ctx}/login/login",
            data: { username: $.trim(username), password: $.trim(password), verifycode: verifycode },
            type: "post",
            dataType: "json",
            success: function (data) {
                if (data.success == true) {
                    var theme = $("#UItheme").val();
                    if (theme == 1) {
                        window.location.href = '${ctx}/home/AdminDefault';
                    }
                    else if (theme == 2) {
                        window.location.href = '${ctx}/home/AdminLTE';
                    }
                    else if (theme == 3) {
                        window.location.href = '${ctx}/home/AdminWindos';
                    }
                } else {
                    dialogAlert(data.message, 0);
                    $("#btnlogin").removeClass('active').removeAttr('disabled');
                    $("#btnlogin").find('span').show();
                    $("#login_verifycode").trigger("click");
                }
            }
        });
    }
    //提示信息
    function formMessage(msg, type) {
        $('.login_tips').parents('dt').remove();
        var _class = "login_tips";
        if (type == 1) {
            _class = "login_tips-succeed";
        }
        $('.form').prepend('<dt><div class="' + _class + '"><i class="fa fa-question-circle"></i>' + msg + '</div></dt>');
    }
</script>
</body>
</html>